package com.bang.sgg.config;

import com.bang.sgg.persist.model.constant.QueueConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: Bang
 * @Date: 2019/11/23 11:29
 * @Description:
 */
@Configuration
public class RabbitmqConfig {

    @Bean
    TopicExchange agentExchange() {
        return ExchangeBuilder.topicExchange(QueueConstant.AGENT_TOPIC_EXCHANGE).durable(true).build();
    }

    @Bean
    Queue helloQueue() {
        return QueueBuilder.durable(QueueConstant.AGENT_HELLO).build();
    }

    @Bean
    Queue worldQueue() {
        return QueueBuilder.durable(QueueConstant.AGENT_WORLD).build();
    }

    @Bean
    Queue hangUpQueue() {
        return QueueBuilder.durable(QueueConstant.AGENT_HANGUP).build();
    }

    @Bean
    Binding helloBind() {
        return BindingBuilder.bind(helloQueue()).to(agentExchange()).with(QueueConstant.AGENT_ROUTE_KEY);
    }

    @Bean
    Binding worldBind() {
        return BindingBuilder.bind(worldQueue()).to(agentExchange()).with(QueueConstant.AGENT_ROUTE_KEY);
    }

    @Bean
    Binding hangUpBind() {
        return BindingBuilder.bind(hangUpQueue()).to(agentExchange()).with(QueueConstant.AGENT_ROUTE_KEY);
    }


    @Bean
    public FanoutExchange fanoutExchange() {
        return ExchangeBuilder.fanoutExchange(QueueConstant.FANOUT_EXCHANGE).durable(true).build();
    }

    @Bean
    public Queue fanoutQueue1() {
        return QueueBuilder.durable(QueueConstant.FANOUT_QUEUE1).build();
    }

    @Bean
    public Queue fanoutQueue2() {
        return QueueBuilder.durable(QueueConstant.FANOUT_QUEUE2).build();
    }

    @Bean
    public Binding binding1() {
        return BindingBuilder.bind(fanoutQueue1()).to(fanoutExchange());
    }

    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange());
    }

}
